<?php
//显示路径及文件夹，文件
function file_lists($path){
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($path."/".$file)) {
                    echo $path.": <font style='color:red'>".$file."</font><br>";//去掉此行显示的是所有的非目录文件
                    file_lists($path."/".$file);
                } else {
                    echo $path.": ".$file."<br>";
                }
            }
        }
    }
}
//显示文件夹及文件，$sign:分隔符，$signNum:文件夹级别分层显示
function file_list($path,$sign,&$signNum){
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($path."/".$file)) {
                	//去掉此行显示的是所有的非目录文件
                    $signNum = $signNum + 1;
                    showFileName($file,$sign,$signNum,true);
                    file_list($path."/".$file,$sign,$signNum);
                } else {
                    showFileName($file,$sign,$signNum,false);
                }
            }
        }
    	$signNum = $signNum - 1;
    }
}
//显示文件名称及分隔符
function showFileName($fileName,$sign,$signNum,$isdir){
	$signDir = "";
	if($isdir){
		while ($signNum>0) {
			$signDir = $signDir.$sign;
			$signNum = $signNum - 1;
		}
		echo $signDir."<font style='color:red'>".$fileName."</font><br>";
	}else{
		while ($signNum>0) {
			$signDir = $signDir.$sign;
			$signNum = $signNum - 1;
		}
		echo $signDir.$fileName."<br>";
	}
}
//div显示文件夹及文件，$sign:分隔符，$signNum:文件夹级别分层显示
function fileDivList($path,$sign,&$signNum){
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($path."/".$file)) {
                    //去掉此行显示的是所有的非目录文件
                    $signNum = $signNum + 1;
                    showDivFile($file,$sign,$signNum,true);
                    echo "<div id='".$file."' class='hidden'>";
                    fileDivList($path."/".$file,$sign,$signNum);
                } else {
                    showDivFile($file,$sign,$signNum,false);
                }
            }
        }
        $signNum = $signNum - 1;
        echo "</div>";
    }
}
//div显示文件名称及分隔符
function showDivFile($fileName,$sign,$signNum,$isdir){
    $signDir = "";
    if($isdir){
        while ($signNum>0) {
            $signDir = $signDir.$sign;
            $signNum = $signNum - 1;
        }
        echo $signDir."<span style='color:red'>".mb_convert_encoding($fileName,"UTF-8","GBK")."</span><br>";
    }else{
        while ($signNum>0) {
            $signDir = $signDir.$sign;
            $signNum = $signNum - 1;
        }
        echo $signDir.mb_convert_encoding($fileName,"UTF-8","GBK")."<br>";
    }
}
//div显示文件夹及文件，$sign:分隔符，$signNum:文件夹级别分层显示
function fileDivListNoSign($path,$sign,&$signNum){
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($path."/".$file)) {
                    //去掉此行显示的是所有的非目录文件
                    $signNum = $signNum + 1;
                    showDivFileNoSign($file,$sign,$signNum,true);
                    echo "<div id='".$file."' class='hidden'>";
                    fileDivListNoSign($path."/".$file,$sign,$signNum);
                } else {
                    showDivFileNoSign($file,$sign,$signNum,false);
                }
            }
        }
        $signNum = $signNum - 1;
        echo "</div>";
    }
}
//div显示文件名称及分隔符
function showDivFileNoSign($fileName,$sign,$signNum,$isdir){
    $signDir = "";
    if($isdir){
        while ($signNum>0) {
            $signDir = $signDir.$sign;
            $signNum = $signNum - 1;
        }
        echo $signDir."<span style='color:red'>".mb_convert_encoding($fileName,"UTF-8","GBK")."</span><br>";
    }else{
        while ($signNum>0) {
            $signDir = $signDir.$sign;
            $signNum = $signNum - 1;
        }
        echo $signDir.mb_convert_encoding($fileName,"UTF-8","GBK")."<br>";
    }
}
?>